/*
 * @Author: wangming
 * @Date: 2021-05-29 14:23:16
 * @LastEditors: wangming
 * @LastEditTime: 2022-10-31 16:18:02
 * @FilePath: /sinocare-detection-sdk-js/main.js
 * @Description: 
 */
import Vue from 'vue';
import App from './App';

Vue.config.productionTip = false;

import Gm501 from 'mcbluetoothsdk/dist/lib/Gm501'
import AnWenAdapter from 'mcbluetoothsdk/dist/lib/AnWenAdapter'
import JinWenAdapter from 'mcbluetoothsdk/dist/lib/JinWenAdapter'
import Ug11Adapter from 'mcbluetoothsdk/dist/lib/Ug11Adapter'
import TrueMetrix from 'mcbluetoothsdk/dist/lib/TrueMetrix'
import Sxl from 'mcbluetoothsdk/dist/lib/Sxl'
import Nf from 'mcbluetoothsdk/dist/lib/Nf'
import Lf from 'mcbluetoothsdk/dist/lib/Lf'
import WlOne from 'mcbluetoothsdk/dist/lib/WlOne' // wl-1直连版
import EA12 from 'mcbluetoothsdk/dist/lib/EA12'
import PC50 from 'mcbluetoothsdk/dist/lib/PC50'
import BP06 from 'mcbluetoothsdk/dist/lib/BP06'
import QNHS from 'mcbluetoothsdk/dist/lib/QNHS'

Vue.prototype.$snQNHS = QNHS
Vue.prototype.$snEA12 = EA12
Vue.prototype.$snBP06 = BP06
Vue.prototype.$snPC50 = PC50
Vue.prototype.$snAW = AnWenAdapter
Vue.prototype.$snJW = JinWenAdapter
Vue.prototype.$snGm501 = Gm501
Vue.prototype.$snUg11 = Ug11Adapter
Vue.prototype.$snTM = TrueMetrix
Vue.prototype.$snSxl = Sxl
Vue.prototype.$snNf = Nf
Vue.prototype.$snLf = Lf
Vue.prototype.$snWlOne = WlOne

Vue.mixin({
	methods: {
		setData: function (obj, callback) {
			let that = this;
			const handleData = (tepData, tepKey, afterKey) => {
				tepKey = tepKey.split('.');
				tepKey.forEach(item => {
					if (tepData[item] === null || tepData[item] === undefined) {
						let reg = /^[0-9]+$/;
						tepData[item] = reg.test(afterKey) ? [] : {};
						tepData = tepData[item];
					} else {
						tepData = tepData[item];
					}
				});
				return tepData;
			};
			const isFn = function (value) {
				return typeof value == 'function' || false;
			};
			Object.keys(obj).forEach(function (key) {
				let val = obj[key];
				key = key.replace(/\]/g, '').replace(/\[/g, '.');
				let front, after;
				let index_after = key.lastIndexOf('.');
				if (index_after != -1) {
					after = key.slice(index_after + 1);
					front = handleData(that, key.slice(0, index_after), after);
				} else {
					after = key;
					front = that;
				}
				if (front.$data && front.$data[after] === undefined) {
					Object.defineProperty(front, after, {
						get() {
							return front.$data[after];
						},
						set(newValue) {
							front.$data[after] = newValue;
							that.$forceUpdate();
						},
						enumerable: true,
						configurable: true
					});
					front[after] = val;
				} else {
					that.$set(front, after, val);
				}
			});
			// this.$forceUpdate();
			isFn(callback) && this.$nextTick(callback);
		}
	}
});

App.mpType = 'app';

const app = new Vue({
	...App
});
app.$mount();
